 <?php                                                                                              
    $csspath = 'mosaic/mosaic.css';
    //$jspath = 'exercises/exercises.js';
 ?>
<?php require_once VIEWPATH.'common/header.php'; ?>
<?php require_once VIEWPATH.'common/sidebar.php'; ?>
 <!--main content start-->
<section id="main-content">
    <section class="wrapper site-min-height">
    <h3><i class="fa fa-angle-right"></i> 在线答题</h3>
        <div class="row mt">
            <div class="col-md-12">
                <div class="content-panel">
                     <div class="main">
                          <div class="mosaic_box">
                              <h3 class="mosaic_title" extID="<?=$info['examinationID']?>" paperID="<?=$info['paperID']?>"><?=$info['paperTitle']?></h3>
                              <?=$body?>
                              <?php if($submit==1){?>
                              <p style="text-align: center; padding: 26px 0 0 0;">
                                  <button id="mosaic_submit" class="btn btn-info btn-ms" style="background-color: #68dff0!important; min-width: 80px;">提交</button>
                              </p>
                              <?php }?>
                          </div>
                          </div>
                     </div>
              </div>
            </div><!-- /content-panel -->
        </div><!-- /row -->
  </section>
</section>
<?php require_once VIEWPATH.'common/footer.php'; ?>
<script type="text/javascript">
  $(".download").click(function(){
    var docpath = $(this).attr("data");
    var filename = $(this).attr("filename");
    window.open("/document/fileDown?docpath="+docpath+"&filename="+filename);
  });
</script>
 <script type="text/javascript">
     $('#mosaic_submit').click(function(){
         var QList = $('.mosaic_box>div');
         var QObj = {};
         var QPaprID = $('.mosaic_box').find('.mosaic_title').attr('paperID');
         var QExtID = $('.mosaic_box').find('.mosaic_title').attr('extID');
         for(var i = 0; i<QList.length; i++){
             var QEle = $(QList[i]);
             var QID = QEle.attr('question');
             var QType = QEle.attr('type');
             switch (QType){
                 case 'radio':
                     var cArr = [];
                     QEle.find('label>input').prop('checked',function( i, val ) {
                         if(val){
                             cArr.push($(this).attr('option_leb'))
                         }
                     });
                     QObj[QID] = JSON.stringify(cArr);
                     break;
                 case 'checkbox':
                     var cArr = [];
                     QEle.find('label>input').prop('checked',function( i, val ) {
                         if(val){
                             cArr.push($(this).attr('option_leb'))
                         }
                     });
                     QObj[QID] = JSON.stringify(cArr);
                     break;
                 case 'text':
                     QObj[QID] = QEle.find('input').val();
                     break;
                 case 'textarea':
                     QObj[QID] = QEle.find('textarea').val();
                     break;
             }
         }
         $.ajax({
             url: '/examination/answer',
             type: 'post',
             data: {
                 id: QPaprID,
                 data:QObj,
                 extID:QExtID
             },
             dataType: 'json',
             success: function(res) {
                 window.location.href='/examination/success?score='+res['data']['score'];
             },
             error: function(res) {

             }
         });
     });
 </script>
